package com.mdd.admin.controller;

import com.alibaba.fastjson2.JSONArray;
import com.mdd.admin.LikeAdminThreadLocal;
import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IDeptFlowService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.DeptFlowCreateValidate;
import com.mdd.admin.validate.DeptFlowUpdateValidate;
import com.mdd.admin.validate.DeptFlowSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.system.SystemDeptSearchValidate;
import com.mdd.admin.vo.DeptFlowListedVo;
import com.mdd.admin.vo.DeptFlowDetailVo;
import com.mdd.admin.vo.system.SystemAuthDeptVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/deptFlow")
@Api(tags = "部门流程关联管理")
public class DeptFlowController {

    @Resource
    IDeptFlowService iDeptFlowService;

    @GetMapping("/list")
    @ApiOperation(value="部门流程关联列表")
    public AjaxResult<PageResult<DeptFlowListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated DeptFlowSearchValidate searchValidate) {
        PageResult<DeptFlowListedVo> list = iDeptFlowService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }
    @GetMapping("/deptList")
    @ApiOperation(value="部门流程关联列表")
    public AjaxResult<PageResult<SystemAuthDeptVo>> deptList(@Validated PageValidate pageValidate,
                                                         @Validated DeptFlowSearchValidate searchValidate) {
        PageResult<SystemAuthDeptVo> list = iDeptFlowService.deptList(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }
    @GetMapping("/detail")
    @ApiOperation(value="部门流程关联详情")
    public AjaxResult<DeptFlowDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        DeptFlowDetailVo detail = iDeptFlowService.detail(id);
        return AjaxResult.success(detail);
    }

    @GetMapping("/detailByAll")
    @ApiOperation(value="部门流程关联详情四表")
    public AjaxResult<DeptFlowDetailVo> detailByAll(Integer deptid,String type) {
        DeptFlowDetailVo detail = iDeptFlowService.detailByAll(deptid,type);
        return AjaxResult.success(detail);
    }

    @GetMapping("/detailByDeptId")
    @ApiOperation(value="部门流程关联详情四表")
    public AjaxResult<DeptFlowDetailVo> detailByDeptId(String proposalType,String type) {
        DeptFlowDetailVo detail = iDeptFlowService.detailByDeptId(proposalType,type);
        return AjaxResult.success(detail);
    }


    @Log(title = "部门流程关联新增")
    @PostMapping("/add")
    @ApiOperation(value="部门流程关联新增")
    public AjaxResult<Object> add(@Validated @RequestBody DeptFlowCreateValidate createValidate) {
        iDeptFlowService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "部门流程关联编辑")
    @PostMapping("/edit")
    @ApiOperation(value="部门流程关联编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody DeptFlowUpdateValidate updateValidate) {
        iDeptFlowService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "部门流程关联删除")
    @PostMapping("/del")
    @ApiOperation(value="部门流程关联删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iDeptFlowService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
